package com.dhcc.sdc.api.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.dhcc.cdc.busi.entity.CdcEmrEntity;
import com.dhcc.cdc.busi.entity.CdcEpisodeEntity;
import com.dhcc.cdc.busi.service.ICdcBsEmrStructService;
import com.dhcc.cdc.busi.service.ICdcEmrService;
import com.dhcc.cdc.busi.service.ICdcEpisodeService;
import com.dhcc.cdc.sys.cache.config.CdcConfigCache;
import com.dhcc.cdc.sys.entity.ConfigurationEntity;
import com.dhcc.cdc.sys.service.IConfigurationService;
import com.dhcc.cdc.util.KettleUtil;
import com.dhcc.core.framework.constant.state.LogSucceed;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.security.ShiroKit;
import com.dhcc.core.framework.util.CommonUtil;
import com.dhcc.core.framework.util.DateUtil;
import com.dhcc.core.framework.util.HttpContextUtil;
import com.dhcc.core.modules.system.entity.User;
import com.dhcc.core.websocket.service.MyWebSocketHandler;
import com.dhcc.sdc.annotion.SdcBusiLog;
import com.dhcc.sdc.annotion.SdcBusiType;
import com.dhcc.sdc.api.dto.DiagnosDataDto;
import com.dhcc.sdc.api.entity.DRGParams;
import com.dhcc.sdc.api.service.ISdsDrgParamsService;
import com.dhcc.sdc.api.service.ISdsToolService;
import com.dhcc.sdc.base.service.IContraindicationService;
import com.dhcc.sdc.busi.entity.*;
import com.dhcc.sdc.busi.service.*;
import com.dhcc.sdc.cdss.dto.ArgumentData;
import com.dhcc.sdc.cdss.dto.GroupInfo;
import com.dhcc.sdc.cdss.entity.SdcCdssItemMatchEntity;
import com.dhcc.sdc.cdss.service.ICdssApiService;
import com.dhcc.sdc.cdss.service.ISdcCdssItemMatchService;
import com.dhcc.sdc.ws.DRG.PreGroupWebService;
import com.dhcc.sdc.ws.DRG.PreGroupWebServiceImplServiceLocator;
import com.dhcc.sds.base.entity.SdsQcentityEntity;
import com.dhcc.sds.base.service.ISdsQcentityService;
import com.dhcc.sds.busi.service.ISdsQcincaseService;
import org.pentaho.di.core.exception.KettleException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.xml.rpc.ServiceException;
import java.math.BigDecimal;
import java.rmi.RemoteException;
import java.text.DecimalFormat;
import java.util.*;

/**
 * @version 1.0 DHCC
 * @Description: 单病种临床交互窗口接口方法
 * @Project Name:
 * @Package Name:
 * @File Name:
 * @author:sunyingjie
 * @date:
 * @Copyright: (c) DHCC All rights reserved.
 */
@Controller
@RequestMapping("${sys.apiPath}/sdstool")
public class SdsToolSdkController {
    @Autowired
    private ISdsToolService sdsToolService;
    @Autowired
    private ISdcBusiQcMrlistService sdcBusiQcMrlistService;
    @Autowired
    private ISdcBusiQcMrlislogService sdcBusiQcMrlislogService;
    @Autowired
    private ISdcBusiQcTriggeredService sdcBusiQcTriggeredService;
    @Autowired
    private ICdcEpisodeService cdcEpisodeService;
    @Autowired
    private ISdsQcentityService sdsQcentityService;
    @Autowired
    private IConfigurationService configurationService;
    @Autowired
    private ISdcCdssItemMatchService sdcCdssItemMatchService;
    @Autowired
    private IContraindicationService contraindicationService;
    @Autowired
    private IIPQCService iipqcService;
    @Autowired
    private ICdssApiService cdssApiService;
    @Autowired
    private ICdcEmrService cdcEmrService;
    @Autowired
    private ICdcBsEmrStructService cdcBsEmrStructService;
    @Autowired
    private ISdcBusiQcfitemExecResultService sdcBusiQcfitemExecResultService ;
    @Autowired
    ISdsDrgParamsService sdsDrgParamsService;
    @Autowired
    ISdcBusiOperationLogService sdcBusiOperationLogService;
    
    @Value("${sys.sysHome}")
    private String sysHome;
    @Value("${sys.kettlePath}")
    private String kettlePath;
    @Value("${sys.jobFileName}")
    private String jobFileName;

    @RequestMapping(value = "/patientInfo")
    public String paAdmPage() {
        return "/backend/cdc/querybypat/querybypat.html";
    }

    /**
     * @param params
     * @return
     * @Description: 初始化患者单病种相关信息
     * @Title: initPatientData
     * @author: sunyingjie
     * @date: 2021年07月16日15:08:52
     */
    @RequestMapping(value = "/init")
    @ResponseBody
    public Object initPatientData(@RequestParam Map<String, Object> params) {
        JSONArray jsonArray = new JSONArray();
        String curEpisodeId = null;// 记录当前请求参数中的就诊号，以便后续与前台js中就诊号作比较
        if (!CommonUtil.isEmpty(params.get("episodeId"))) {
            curEpisodeId = params.get("episodeId").toString();
            // 查询数据中心的对应的就诊id
            Map map = new HashMap();
            map.put("xcode", params.get("episodeId"));
            List<CdcEpisodeEntity> cdcEpisods = cdcEpisodeService.list(map);
            if (cdcEpisods.size() == 0) {
                //作业路径
                String jobFile = sysHome + kettlePath + "paadmById/sds.kjb";
                //同步数据
                try {
                    KettleUtil.runPaAdmJob(String.valueOf(params.get("episodeId")), jobFile, 10);
                } catch (KettleException e) {
                    e.printStackTrace();
                }
            }
            // 结果返回结构
            jsonArray = sdsToolService.analysisClinicData(params);
        }
        return R.ok().put("data", jsonArray).put("curEpisodeId", curEpisodeId);
    }

    /**
     * @param params
     * @return
     * @Description: 获取单病种浮窗相关配置
     * @Title: getConfig
     * @author: yanghangwei
     * @date: 2024年03月12日15:08:52
     */
    @RequestMapping(value = "/config")
    @ResponseBody
    public Object getConfig(@RequestParam Map<String, Object> params) {
        JSONArray jsonArray = new JSONArray();
        String[] codes = {"float_drg_show","float_pre_filling","CDSSServer","WebSocket_Entity"};
        Map<String,String> map = new HashMap<>();
        for (String code : codes) {
            String keyValue = CdcConfigCache.me().getValueByKey("SDS", code);
            if ("WebSocket_Entity".equals(code)) {
                StringBuilder entityIds = new StringBuilder("");
                String[] abbrevs = keyValue.split(",");
                for (String abbrev : abbrevs) {
                    Wrapper<SdsQcentityEntity> spcWpr = new EntityWrapper<>();
                    spcWpr.eq("abbrev", abbrev);
                    SdsQcentityEntity sdsQcentityEntity = sdsQcentityService.selectOne(spcWpr);
                    entityIds.append(sdsQcentityEntity.getId()).append(",");
                }
                entityIds.deleteCharAt(entityIds.lastIndexOf(","));
                map.put(code, entityIds.toString());
            } else {
                map.put(code, keyValue);
            }
        }
        return R.ok().put("data", map);
    }

    /**
     * @param params
     * @return
     * @Description: 分析临床交互数据
     * @Title: analysisClinicData
     * @author: sunyingjie
     * @date: 2021年07月16日15:08:52
     */
    @RequestMapping(value = "/analysis")
    @ResponseBody
    public Object analysisClinicData(@RequestParam Map<String, Object> params) {
        JSONArray jsonArray = new JSONArray();
        String curEpisodeId = null;// 记录当前请求参数中的就诊号，以便后续与前台js中就诊号作比较
        if (!CommonUtil.isEmpty(params.get("episodeId"))) {
            curEpisodeId = params.get("episodeId").toString();
            /*//作业路径
            String jobFile = sysHome + kettlePath + "paadmById/sds.kjb";
            //同步数据
            try {
                KettleUtil.runPaAdmJob(String.valueOf(params.get("episodeId")), jobFile, 10);
            } catch (KettleException e) {
                e.printStackTrace();
            }*/
            // 结果返回结构
            jsonArray = sdsToolService.analysisClinicData(params);
        }
        return R.ok().put("data", jsonArray).put("curEpisodeId", curEpisodeId);
    }

    /**
     * @Description: 同步患者指定业务数据
     * @Title: synClinicData
     * @author: sunyingjie
     * @date: 2023年05月08日15:08:52
     */
    @RequestMapping(value = "/synData")
    @ResponseBody
    public Object synClinicData(@RequestParam Map<String, Object> params) {
        JSONArray jsonArray = new JSONArray();
        String curEpisodeId = null;// 记录当前请求参数中的就诊号，以便后续与前台js中就诊号作比较
        if (!CommonUtil.isEmpty(params.get("episodeId"))) {
            curEpisodeId = params.get("episodeId").toString();
            String dataType = params.get("dataType").toString();
            //作业路径
            String jobFile = sysHome + kettlePath + "subData/";
            if (CommonUtil.equals(dataType, "admInfo")) {
                jobFile = jobFile+ "paadm.kjb";
            } else if (CommonUtil.equals(dataType, "diagInfo")) {
                jobFile = jobFile+ "diagnosis.kjb";
            } else if (CommonUtil.equals(dataType, "orderInfo")) {
                jobFile = jobFile+ "orderExec.kjb";
            } else if (CommonUtil.equals(dataType, "surgeryInfo")) {
                jobFile = jobFile+ "surgery.kjb";
            } else if (CommonUtil.equals(dataType, "signInfo")) {
                jobFile = jobFile+ "sign.kjb";
            } else if (CommonUtil.equals(dataType, "examInfo")) {
                jobFile = jobFile+ "exam.kjb";
            } else if (CommonUtil.equals(dataType, "lisInfo")) {
                jobFile = jobFile+ "lis.kjb";
            } else if (CommonUtil.equals(dataType, "emrInfo")) {
                jobFile = jobFile+ "emr.kjb";
            } else if (CommonUtil.equals(dataType, "nurInfo")) {
                jobFile = jobFile+ "nur.kjb";
            }
            try {
                //同步数据
                KettleUtil.runPaAdmJob(String.valueOf(params.get("episodeId")), jobFile, 10);
            } catch (KettleException e) {
                e.printStackTrace();
            }
            MyWebSocketHandler.fanoutMessage(curEpisodeId);
            //如果同步数据类型是病历，则解析病历数据
            if (CommonUtil.equals(dataType, "emrInfo")){
                String nlpUrl = CdcConfigCache.me().getValueByKey("SDS", "SDAnalysisServer");
                // 查询数据中心的对应的就诊id
                Map map = new HashMap();
                map.put("xcode", curEpisodeId);
                List<CdcEpisodeEntity> cdcEpisodes = cdcEpisodeService.list(map);
                if (cdcEpisodes.size() == 0) {
                    CdcEpisodeEntity cdcEpisode = cdcEpisodes.get(0);
                    String patientId = cdcEpisode.getId().toString();
                    // 获取病历数据
                    List<CdcEmrEntity> emrList = cdcEmrService.selectList(new EntityWrapper<CdcEmrEntity>().eq("episode_id", patientId).between("update_date", DateUtil.getDay() + " 00:00:00", DateUtil.getDay() + " 23:59:59"));
                    cdcBsEmrStructService.emrStructByNLP(nlpUrl, emrList);
                }
            }
        }
        return R.ok();
    }

    /**
     * @param params
     * @return
     * @Description: 跳转禁忌症页面
     * @Title: showCi
     * @author: sunyingjie
     * @date: 2021年09月16日15:08:52
     */
    @RequestMapping(value = "/showCI")
    public String showCi(@RequestParam Map<String, Object> params, Model model) {
        String episodeId = params.get("patientId").toString();
        Long entityId = Long.valueOf(params.get("entityId").toString());
        String modifyUserId = String.valueOf(params.get("modifyUserId"));
        String modifyUserName = String.valueOf(params.get("modifyUserName"));
        Long ciId = null;
        Long recordId = null;
        Long eventId = null;
        if (CommonUtil.isNotEmpty(params.get("ciId"))) {
            ciId = Long.valueOf(params.get("ciId").toString());
        }
        if (CommonUtil.isNotEmpty(params.get("recordId"))) {
            recordId = Long.valueOf(params.get("recordId").toString());
        }
        if (CommonUtil.isNotEmpty(params.get("eventId"))) {
            eventId = Long.valueOf(params.get("eventId").toString());
        }
        // 查询数据中心的对应的就诊id
        Map map = new HashMap();
        map.put("xcode", episodeId);
        List<CdcEpisodeEntity> cdcEpisods = cdcEpisodeService.list(map);
        if (cdcEpisods.size() == 0) {
            return "";
        }
        Long patientId = cdcEpisods.get(0).getId();
        // 获取入组ID
        Wrapper<SdcBusiQcMrlistEntity> wpr = new EntityWrapper<>();
        wpr.eq("entity_Id", entityId).eq("episode_id", patientId);
        SdcBusiQcMrlistEntity qcin = sdcBusiQcMrlistService.selectOne(wpr);
        Long inCaseId = qcin.getId();
        params.put("inCaseId", inCaseId);
        // 获取病例病种禁忌症
        model.addAttribute("patientId", patientId);
        model.addAttribute("entityId", entityId);
        model.addAttribute("inCaseId", inCaseId);
        model.addAttribute("modifyUserId", modifyUserName);
        model.addAttribute("modifyUserName", modifyUserName);
        model.addAttribute("recordId", recordId);
        model.addAttribute("eventId", eventId);
        return "/backend/sds/sdstool/sdsci.html";
    }

    /**
     * @param params
     * @return
     * @Description: 获取禁忌症信息
     * @Title: getCIInfo
     * @author: sunyingjie
     * @date: 2021年09月16日15:08:52
     */
    @RequestMapping(value = "/getCIInfo")
    @ResponseBody
    public Object getCIInfo(@RequestParam Map<String, Object> params) {
        String patientId = params.get("patientId").toString();
        // 查询数据中心的对应的就诊id
        Map map = new HashMap();
        map.put("xcode", patientId);
        List<CdcEpisodeEntity> cdcEpisods = cdcEpisodeService.list(map);
        if (cdcEpisods.size() == 0) {
            return "";
        }
        Long episodeId = cdcEpisods.get(0).getId();
        params.put("episodeId", episodeId);
        return sdsToolService.getCIs(params);
    }

    /**
     * @param params
     * @return
     * @Description: 保存禁忌症确认结果
     * @Title: saveCiInfo
     * @author: sunyingjie
     * @date: 2021年09月16日15:08:52
     */
    @RequestMapping(value = "/saveCIInfo")
    @ResponseBody
    @SdcBusiLog(sdcBusiType = SdcBusiType.CI_SAVE)
    public Object saveCiInfo(@RequestParam Map<String, Object> params) {
        // 查询数据中心的对应的就诊id
        String episodeId = params.get("episodeId").toString();
        Map map = new HashMap();
        map.put("xcode", episodeId);
        List<CdcEpisodeEntity> cdcEpisods = cdcEpisodeService.list(map);
        if (cdcEpisods.size() == 0) {
            return "";
        }
        params.put("episodeId", cdcEpisods.get(0).getId());
        // 保存禁忌信息到相关项目结果表
        sdsToolService.saveCiInfo(params);
        return R.ok();
    }

    /**
     * @param params
     * @return
     * @Description: 跳转表单填报页面
     * @Title: showForm
     * @author: sunyingjie
     * @date: 2021年09月16日15:08:52
     */
//    @RequestMapping(value = "/showForm")
//    public String showForm(@RequestParam Map<String, Object> params, Model model) {
//        String episodeId = params.get("patientId").toString();
//        Long entityId = Long.valueOf(params.get("entityId").toString());
//        String modifyUserId = params.get("modifyUserId").toString();
//        String modifyUserName = params.get("modifyUserName").toString();
//        // 查询数据中心的对应的就诊id
//        Map map = new HashMap();
//        map.put("xcode", episodeId);
//        List<CdcEpisodeEntity> cdcEpisods = cdcEpisodeService.list(map);
//        if (cdcEpisods.size() == 0) {
//            return "";
//        }
//        Long patientId = cdcEpisods.get(0).getId();
//        // 获取入组ID
//        Wrapper<SdcBusiQcMrlistEntity> wpr = new EntityWrapper<>();
//        wpr.eq("entity_Id", entityId).eq("episode_id", patientId);
//        SdcBusiQcMrlistEntity qcin = sdcBusiQcMrlistService.selectOne(wpr);
//        Long inCaseId = qcin.getId();
//        // 查询入组详细
//        SdcBusiQcMrlistEntity mrEntity = sdcBusiQcMrlistService.selectById(inCaseId);
//        // 查询病种详细
//        SdsQcentityEntity qcEntity = sdsQcentityService.selectById(mrEntity.getEntityId());
//        // 单病种医生是否可以直接上报配置
//        String formCheckType = CdcConfigCache.me().getValueByKey("SDS", "SDFormCheckType");
//        model.addAttribute("mrListId", inCaseId);
//        model.addAttribute("entityId", mrEntity.getEntityId());
//        model.addAttribute("episodeId", mrEntity.getEpisodeId());
//        model.addAttribute("execUser", modifyUserId);
//        model.addAttribute("formCheckType", formCheckType);
//        model.addAttribute("checkPerm", 0);
//        return "/backend/sds/sdsqcformshow/" + qcEntity.getAbbrev() + ".html";
//    }

    /**
     * @param params
     * @return
     * @Description: 跳转表单填报页面
     * @Title: showForm
     * @author: yanghangwei
     * @date: 2024年01月25日15:08:52
     */

    @RequestMapping(value = "/showForm")
    public String showForm(@RequestParam Map<String, Object> params, Model model) {
        String execUser = "unknown";
        if (CommonUtil.isNotEmpty(params.get("execUser"))) {
            execUser = java.net.URLDecoder.decode(params.get("execUser").toString());
        } else {
            User user = ShiroKit.getUser();
            if (user!=null) {
                execUser = user.getLoginName();
            }
        }
        String episodeId = params.get("patientId").toString();
        Long entityId = Long.valueOf(params.get("entityId").toString());
        String modifyUserId = params.get("modifyUserId").toString();
        String modifyUserName = params.get("modifyUserName").toString();
        // 查询数据中心的对应的就诊id
        Map map = new HashMap();
        map.put("xcode", episodeId);
        List<CdcEpisodeEntity> cdcEpisods = cdcEpisodeService.list(map);
        if (cdcEpisods.size() == 0) {
            return "";
        }
        Long patientId = cdcEpisods.get(0).getId();
        // 获取入组ID
        Wrapper<SdcBusiQcMrlistEntity> wpr = new EntityWrapper<>();
        wpr.eq("entity_Id", entityId).eq("episode_id", patientId).eq("state","I");
        SdcBusiQcMrlistEntity qcin = sdcBusiQcMrlistService.selectOne(wpr);
        Long inCaseId = qcin.getId();
        // 查询入组详细
        SdcBusiQcMrlistEntity qcMrEntity = sdcBusiQcMrlistService.selectById(inCaseId);
        // 查询病种详细
        SdsQcentityEntity qcEntity = sdsQcentityService.selectById(qcMrEntity.getEntityId());
        // 查询上报入组详情
//        SdsQcincaseEntity mrEntity = sdsQcincaseService.selectByEpisodeIdAndEntityId(patientId, qcMrEntity.getEntityId());
//        if (mrEntity == null){
//            mrEntity = new SdsQcincaseEntity();
//            SdcBusiQcMrlistEntity qcMrlistEntity = sdcBusiQcMrlistService.getByEpisodeId(patientId);
//            mrEntity.setEntityId(qcMrlistEntity.getEntityId());
//            mrEntity.setEpisodeId(qcMrlistEntity.getEpisodeId());
//            mrEntity.setState("P");
//            mrEntity.setGroupStatus("SysRec");
//            mrEntity.setFillingStatus("NotFilled");
//            mrEntity.setReportStatus("NotUp");
//            sdsQcincaseService.insert(mrEntity);
//        }
        // 单病种医生是否可以直接上报配置
        String formCheckType = CdcConfigCache.me().getValueByKey("SDS", "SDFormCheckType");

        model.addAttribute("mrType",1);
        model.addAttribute("mrListId", qcMrEntity.getId());
        model.addAttribute("entityId", qcMrEntity.getEntityId());
        model.addAttribute("episodeId", qcMrEntity.getEpisodeId());
        model.addAttribute("execUser", execUser);
        model.addAttribute("formCheckType", formCheckType);
        model.addAttribute("checkPerm", 0);
        return "/backend/sds/sdsqcformshow/" + qcEntity.getAbbrev() + ".html";
    }

    /**
     * @param params
     * @return
     * @Description: 跳转评估页面
     * @Title: showASMT
     * @author: sunyingjie
     * @date: 2021年09月16日15:08:52
     */
    @RequestMapping(value = "/showASMT")
    public String showASMT(@RequestParam Map<String, Object> params, Model model) {
        String episodeId = params.get("episodeId").toString();
        String locId = params.get("locId").toString();
        Long entityId = Long.valueOf(params.get("entityId").toString());
        String modifyUserId = String.valueOf(params.get("modifyUserId"));
        String modifyUserName = String.valueOf(params.get("modifyUserName"));
        String desc = String.valueOf(params.get("desc"));
        if (CommonUtil.isEmpty(params.get("itemId"))) {
            return "";
        }
        Long itemId = Long.valueOf(params.get("itemId").toString());
        String nodeId = params.get("nodeId").toString();
        // 查询数据中心的对应的就诊id
        Map map = new HashMap();
        map.put("xcode", episodeId);
        List<CdcEpisodeEntity> cdcEpisods = cdcEpisodeService.list(map);
        if (cdcEpisods.size() == 0) {
            return "";
        }
        Long patientId = cdcEpisods.get(0).getId();

        // 获取项目关联评估表Id
        /*Wrapper<SdcCdssEvalEntity> evalWpr = new EntityWrapper<>();
        evalWpr.eq("item_id", itemId).eq("qcentity_id", entityId);
        SdcCdssEvalEntity sdcCdssEval = sdcCdssEvalService.selectOne(evalWpr);
        Long asmtId = sdcCdssEval.getAssessmentId();*/
        Wrapper<SdcCdssItemMatchEntity> evalWpr = new EntityWrapper<>();
        evalWpr.eq("item_id", itemId);
        evalWpr.eq("entity_id", entityId);
        SdcCdssItemMatchEntity cdssEvalMatchEntity = sdcCdssItemMatchService.selectOne(evalWpr);

        Long asmtId = 0l;
        if (cdssEvalMatchEntity != null) {
            asmtId = cdssEvalMatchEntity.getMatchId();
        }

        // 获取入组ID
        Wrapper<SdcBusiQcMrlistEntity> wpr = new EntityWrapper<>();
        wpr.eq("entity_Id", entityId).eq("episode_id", patientId);
        SdcBusiQcMrlistEntity qcin = sdcBusiQcMrlistService.selectOne(wpr);
        Long inCaseId = qcin.getId();

        model.addAttribute("locId", locId);
        model.addAttribute("patientId", patientId);
        model.addAttribute("episodeId", episodeId);//his就诊号
        model.addAttribute("entityId", entityId);
        model.addAttribute("inCaseId", inCaseId);
        model.addAttribute("modifyUserId", modifyUserId);
        model.addAttribute("modifyUserName", modifyUserName);
        model.addAttribute("asmtId", asmtId);
        model.addAttribute("nodeId", nodeId);
        model.addAttribute("desc", desc);
        return "/backend/sds/sdstool/sdsasmt2.html";
    }

    /**
     * @param params
     * @return
     * @Description: 获取评估历史
     * @Title: getAsmtNodes
     * @author: sunyingjie
     * @date: 2022年07月21日15:08:52
     */
    @RequestMapping(value = "/getAsmtNodes")
    @ResponseBody
    public Object getAsmtNodes(@RequestParam Map<String, Object> params) {
        return sdsToolService.getAsmtNodes(params);
    }

    /**
     * @param params
     * @return
     * @Description: 获取评估量表信息
     * @Title: getAsmtInfo
     * @author: sunyingjie
     * @date: 2021年09月16日15:08:52
     */
    @RequestMapping(value = "/getAsmtInfo")
    @ResponseBody
    public Object getAsmtInfo(@RequestParam Map<String, Object> params) {
        return sdsToolService.getAsmtInfo(params);
    }

    /**
     * @param params
     * @return
     * @Description: 获取节点评估信息
     * @Title: getNodeInfo
     * @author: sunyingjie
     * @date: 2022年07月21日15:08:52
     */
    @RequestMapping(value = "/getNodeInfo")
    @ResponseBody
    public Object getNodeInfo(@RequestParam Map<String, Object> params) {
        return sdsToolService.getNodeInfo(params);
    }

    /**
     * @param params
     * @return
     * @Description: 获取自动评估信息
     * @Title: getAutoNodeInfo
     * @author: zhangdc
     * @date: 2023年03月30日15:08:52
     */
    @RequestMapping(value = "/getAutoNodeInfo")
    @ResponseBody
    public Object getAutoNodeInfo(@RequestParam Map<String, Object> params) {
        return sdsToolService.gettAutoNodeInfo(params);
    }

    /**
     * @param params
     * @return
     * @Description: 自动评估保存至t_sdc_busi_evaluation_his
     * @Title: saveAiNodeInfo
     * @author: ruimin
     * @date: 2023年12月13日
     */
    @RequestMapping(value = "/saveAiNodeInfo")
    @ResponseBody
    public void saveAiNodeInfo(@RequestParam Map<String, Object> params) {
         sdsToolService.saveAiNodeInfo(params);
    }

    /**
     * @param params
     * @return
     * @Description: 保存评估结果
     * @Title: saveAsmtInfo
     * @author: sunyingjie
     * @date: 2021年09月16日15:08:52
     */
    @RequestMapping(value = "/saveAsmtInfo")
    @ResponseBody
    @SdcBusiLog(sdcBusiType = SdcBusiType.EVAL_SAVE)
    public Object saveAsmtInfo(@RequestParam Map<String, Object> params) {
        // 保存禁忌信息到相关项目结果表
        sdsToolService.saveAsmtInfo(params);
        return R.ok();
    }

    /**
     * 手动出组
     * @param params
     * @return
     */
    @RequestMapping(value = "/changeGroup")
    @ResponseBody
    @SdcBusiLog(sdcBusiType = SdcBusiType.OUTOFGROUP_SAVE)
    public Object changeGroup(@RequestParam Map<String,Object> params){
        Long mrlistId = Long.valueOf(params.get("mrListId").toString());
        String modifyUserId = String.valueOf(params.get("modifyUserId"));
        String modifyUserName = String.valueOf(params.get("modifyUserName"));
        Date execDate = new Date();
        SdcBusiQcMrlistEntity sdcBusiQcMrlistEntity = sdcBusiQcMrlistService.selectById(mrlistId);
        if (CommonUtil.isNotEmpty(sdcBusiQcMrlistEntity)){
            sdcBusiQcMrlistEntity.setOutDate(execDate);
            sdcBusiQcMrlistEntity.setOutTime(execDate);
            sdcBusiQcMrlistEntity.setOutDocId(modifyUserId);
            sdcBusiQcMrlistEntity.setGroupStatus("ActivePart");
            sdcBusiQcMrlistEntity.setState("O");
            sdcBusiQcMrlistEntity.updateAllColumnById();
            SdcBusiQcMrlislogEntity qcMrlislog = new SdcBusiQcMrlislogEntity();
            qcMrlislog.setMrlistId(mrlistId);
            qcMrlislog.setOperDate(execDate);
            qcMrlislog.setOperReason(String.valueOf(params.get("reason")));
            qcMrlislog.setOperState("O");
            qcMrlislog.setOperResume("在院过程质控出组");
            qcMrlislog.setOperUser(modifyUserName);
            sdcBusiQcMrlislogService.insert(qcMrlislog);
            Long episodeId = sdcBusiQcMrlistEntity.getEpisodeId();
            Long entityId = sdcBusiQcMrlistEntity.getEntityId();
            //出组时删除过程质控触发项
            Wrapper<SdcBusiQcTriggeredEntity> triWrapper = new EntityWrapper<SdcBusiQcTriggeredEntity>() ;
            triWrapper.eq("episode_id",sdcBusiQcMrlistEntity.getEpisodeId());
            sdcBusiQcTriggeredService.delete(triWrapper);
            //出组时删除预填报内容
            Wrapper<SdcBusiQcitemExecResultEntity> wrapperExec = new EntityWrapper<>();
            wrapperExec.eq("in_case_id",mrlistId);
            sdcBusiQcfitemExecResultService.delete(wrapperExec);
            //HIS图标状态更新
            Map hisMap = new HashMap();
            CdcEpisodeEntity episode = cdcEpisodeService.selectById(episodeId);
            SdsQcentityEntity qcentity = sdsQcentityService.selectById(entityId);
            hisMap.put("episodeId", episode.getXcode());
            hisMap.put("diseaseType", qcentity.getBtDesc());
            hisMap.put("modifyUser", modifyUserId);
            hisMap.put("isActive", "0");
            sdsToolService.pushIntheInfo2His(hisMap);
        }
        return R.ok();
    }

    /**
     * @param params
     * @return
     * @Description: 跳转医嘱关联处置页面
     * @Title: showOrder
     * @author: sunyingjie
     * @date: 2021年09月16日15:08:52
     */
    @RequestMapping(value = "/showOrder")
    public String showOrder(@RequestParam Map<String, Object> params, Model model) {
        Long episodeId = Long.valueOf(params.get("patientId").toString());
        Long entityId = Long.valueOf(params.get("entityId").toString());
        String modifyUserId = String.valueOf(params.get("modifyUserId"));
        String modifyUserName = String.valueOf(params.get("modifyUserName"));
        String nodeId = params.get("nodeId").toString();
        String planType = params.get("planType").toString();

        // 查询数据中心的对应的就诊id
        Map map = new HashMap();
        map.put("xcode", episodeId);
        List<CdcEpisodeEntity> cdcEpisods = cdcEpisodeService.list(map);
        if (cdcEpisods.size() == 0) {
            return "";
        }
        Long patientId = cdcEpisods.get(0).getId();
        // 获取入组ID
        Wrapper<SdcBusiQcMrlistEntity> wpr = new EntityWrapper<>();
        wpr.eq("entity_Id", entityId).eq("episode_id", patientId);
        SdcBusiQcMrlistEntity qcin = sdcBusiQcMrlistService.selectOne(wpr);
        Long inCaseId = qcin.getId();

        model.addAttribute("patientId", patientId);
        model.addAttribute("episodeId", episodeId);
        model.addAttribute("entityId", entityId);
        model.addAttribute("inCaseId", inCaseId);
        model.addAttribute("modifyUserId", modifyUserId);
        model.addAttribute("modifyUserName", modifyUserName);
        model.addAttribute("nodeId", nodeId);
        model.addAttribute("planType", planType);
        return "/backend/sds/sdstool/sdsorder.html";
    }

    /**
     * @param params
     * @return
     * @Description: 获取医嘱项
     * @Title: getOrderInfo
     * @author: sunyingjie
     * @date: 2021年09月16日15:08:52
     */
    @RequestMapping(value = "/getOrderInfo")
    @ResponseBody
    public JSONArray getOrderInfo(@RequestParam Map<String, Object> params) {
        return sdsToolService.getOrderInfo(params);
    }

    /**
     * @param params =>orderIds = 11||1#12||2#13||1  多个医嘱项id以#分割
     * @Description: 把页面勾选的医嘱项插入东华HIS医嘱待审核列表
     * @Title: addOrderToHis
     * @return: Object
     * @author: sunyingjie
     * @date:2021年10月18日 下午2:26:22
     */
    @RequestMapping(value = "/addOrderToHis")
    @ResponseBody
    @SdcBusiLog(sdcBusiType = SdcBusiType.ORDER_SAVE)
    public Object addOrderToHis(@RequestParam Map<String, Object> params) {
        return sdsToolService.addOrderToHis(params);
    }

    /**
     * @param params
     * @return
     * @Description: 跳转其他事件处置页面
     * @Title: showOther
     * @author: sunyingjie
     * @date: 2021年09月16日15:08:52
     */
    @RequestMapping(value = "/showOther")
    public String showOther(@RequestParam Map<String, Object> params, Model model) {
        Long episodeId = Long.valueOf(params.get("patientId").toString());
        Long entityId = Long.valueOf(params.get("entityId").toString());
        String modifyUserId = String.valueOf(params.get("modifyUserId"));
        String modifyUserName = String.valueOf(params.get("modifyUserName"));
        Long eventId = Long.valueOf(params.get("eventId").toString());
        Long recordId = Long.valueOf(params.get("recordId").toString());

        // 查询数据中心的对应的就诊id
        Map map = new HashMap();
        map.put("xcode", episodeId);
        List<CdcEpisodeEntity> cdcEpisods = cdcEpisodeService.list(map);
        if (cdcEpisods.size() == 0) {
            return "";
        }
        Long patientId = cdcEpisods.get(0).getId();
        // 获取入组ID
        Wrapper<SdcBusiQcMrlistEntity> wpr = new EntityWrapper<>();
        wpr.eq("entity_Id", entityId).eq("episode_id", patientId);
        SdcBusiQcMrlistEntity qcin = sdcBusiQcMrlistService.selectOne(wpr);
        Long inCaseId = qcin.getId();

        model.addAttribute("patientId", patientId);
        model.addAttribute("episodeId", episodeId);
        model.addAttribute("entityId", entityId);
        model.addAttribute("inCaseId", inCaseId);
        model.addAttribute("modifyUserId", modifyUserId);
        model.addAttribute("modifyUserName", modifyUserName);
        model.addAttribute("recordId", recordId);
        model.addAttribute("eventId", eventId);
        return "/backend/sds/sdstool/sdsother.html";
    }

    /**
     * 跳转手动出组
     * @param params
     * @param model
     * @return
     */
    @RequestMapping(value = "/outOfGroup")
    public String outofGroup(@RequestParam Map<String,Object> params, Model model){
        Long entityId = Long.valueOf(params.get("entityId").toString());
        String modifyUserId = String.valueOf(params.get("modifyUserId"));
        String modifyUserName = String.valueOf(params.get("modifyUserName"));
        // 查询数据中心的对应的就诊id
        Map map = new HashMap();
        map.put("xcode", params.get("patientId"));
        List<CdcEpisodeEntity> cdcEpisods = cdcEpisodeService.list(map);
        if (cdcEpisods.size() == 0) {
            return "";
        }
        Long patientId = cdcEpisods.get(0).getId();
        // 获取入组ID
        Wrapper<SdcBusiQcMrlistEntity> wpr = new EntityWrapper<>();
        wpr.eq("entity_Id", entityId).eq("episode_id", patientId);
        SdcBusiQcMrlistEntity qcin = sdcBusiQcMrlistService.selectOne(wpr);
        model.addAttribute("mrListId",qcin.getId());
        model.addAttribute("modifyUserId",modifyUserId);
        model.addAttribute("modifyUserName",modifyUserName);
        return "/backend/sds/sdstool/outofgroup.html";
    }

    /**
     * @param params
     * @return
     * @Description: 跳转诊疗详细页面
     * @Title: showTreatDetail
     * @author: sunyingjie
     * @date: 2022年09月16日15:08:52
     */
    @RequestMapping(value = "/showTreatDetail")
    public String showTreatDetail(@RequestParam Map<String, Object> params, Model model) {
        Long entityId = Long.valueOf(params.get("entityId").toString());
        // 查询数据中心的对应的就诊id
        Map map = new HashMap();
        map.put("xcode", params.get("patientId"));
        List<CdcEpisodeEntity> cdcEpisods = cdcEpisodeService.list(map);
        if (cdcEpisods.size() == 0) {
            return "";
        }
        Long patientId = cdcEpisods.get(0).getId();
        model.addAttribute("patientId", patientId);
        model.addAttribute("entityId", entityId);
        return "/backend/sds/sdstool/sdstreatdetail.html";
    }

    /**
     * @param params
     * @return
     * @Description: 获取诊疗详细信息
     * @Title: getTreatDetailInfo
     * @author: sunyingjie
     * @date: 2022年09月16日15:08:52
     */
    @RequestMapping(value = "/getTreatDetailInfo")
    @ResponseBody
    public JSONArray getTreatDetailInfo(@RequestParam Map<String, Object> params) {
        return sdsToolService.getTreatDetailInfo(params);
    }

    /**
     * @param params
     * @return
     * @Description: 获取诊疗信息(浮窗单次请求)
     * @Title: reloadTreatInfo
     * @author: sunyingjie
     * @date: 2022年11月07日16:09:53
     */
    @RequestMapping(value = "/reloadTreatInfo")
    @ResponseBody
    public JSONArray reloadTreatInfo(@RequestParam Map<String, Object> params) {
        JSONArray jsonArray = new JSONArray();
        if (CommonUtil.isEmpty(params.get("episodeId"))||CommonUtil.isEmpty(params.get("entityId"))) {
            return jsonArray;
        }
        String episodeId = String.valueOf(params.get("episodeId")); // 就诊号
        String entityId = String.valueOf(params.get("entityId")); // 病种id
        // 查询数据中心的对应的就诊id
        Map map = new HashMap();
        map.put("xcode", episodeId);
        List<CdcEpisodeEntity> cdcEpisods = cdcEpisodeService.list(map);
        if (cdcEpisods.size() == 0) {
            return jsonArray;
        }
        episodeId = cdcEpisods.get(0).getId().toString();
        params.put("episodeId", episodeId);
        SdsQcentityEntity inthe = sdsQcentityService.selectById(entityId);
        // 获取患者全量信息
        ArgumentData argumentData = cdssApiService.createArgumentData(episodeId);
        GroupInfo groupInfo = new GroupInfo();
        groupInfo.setName("SDS");
        groupInfo.setSingleDisease(inthe.getBtDesc());
        groupInfo.setSingleDiseaseId(inthe.getId().toString());
        argumentData.setGroupInfo(groupInfo);
        // 调用cdss接口，返回请求类型数据
        JSONArray cdssResult = new JSONArray();
        // 一次请求全部数据
        String typeStr = ArgumentData.ParamType.RecommendLabExam + "," + ArgumentData.ParamType.AssistTreat + "," + ArgumentData.ParamType.RecommendNursing + "," + ArgumentData.ParamType.RecommendAssess;
        argumentData.setType(typeStr);
        cdssResult.addAll(cdssApiService.cdssData(argumentData).getJSONArray("cdssInfo"));
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("cdssInfo",cdssApiService.filterResult(episodeId, inthe.getId(), cdssResult));
        resultMap.put("ciInfo",reloadCIInfo(params));
        jsonArray.add(cdssApiService.filterResult(episodeId, inthe.getId(), cdssResult));
        jsonArray.add(reloadCIInfo(params));
        return jsonArray;
    }

    /**
     * @param params
     * @return
     * @Description: 获取质控信息(浮窗单次请求)
     * @Title: reloadQCInfo
     * @author: sunyingjie
     * @date: 2022年11月07日16:09:53
     */
    @RequestMapping(value = "/reloadQCInfo")
    @ResponseBody
    public JSONArray reloadQCInfo(@RequestParam Map<String, Object> params) {
        JSONArray jsonArray = new JSONArray();
        if (CommonUtil.isEmpty(params.get("episodeId"))||CommonUtil.isEmpty(params.get("entityId"))) {
            return jsonArray;
        }
        String episodeId = String.valueOf(params.get("episodeId")); // 就诊号
        String entityId = String.valueOf(params.get("entityId")); // 病种id
        // 查询数据中心的对应的就诊id
        Map map = new HashMap();
        map.put("xcode", episodeId);
        List<CdcEpisodeEntity> cdcEpisods = cdcEpisodeService.list(map);
        if (cdcEpisods.size() == 0) {
            return jsonArray;
        }
        episodeId = cdcEpisods.get(0).getId().toString();
        params.put("episodeId", episodeId);
        // 禁忌症信息
        return iipqcService.QCInfo(Long.valueOf(episodeId), Long.valueOf(entityId));
    }

    /**
     * @param params
     * @return
     * @Description: 获取禁忌信息(浮窗单次请求)
     * @Title: reloadCIInfo
     * @author: sunyingjie
     * @date: 2022年11月07日16:09:53
     */
    @RequestMapping(value = "/reloadCIInfo")
    @ResponseBody
    public JSONArray reloadCIInfo(@RequestParam Map<String, Object> params) {
        JSONArray jsonArray = new JSONArray();
        if (CommonUtil.isEmpty(params.get("episodeId"))||CommonUtil.isEmpty(params.get("entityId"))) {
            return jsonArray;
        }
        String episodeId = String.valueOf(params.get("episodeId")); // 就诊号
        String entityId = String.valueOf(params.get("entityId")); // 病种id
        // 查询数据中心的对应的就诊id
        Map map = new HashMap();
        map.put("xcode", episodeId);
        List<CdcEpisodeEntity> cdcEpisods = cdcEpisodeService.list(map);
        if (cdcEpisods.size() == 0) {
            return jsonArray;
        }
        episodeId = cdcEpisods.get(0).getId().toString();
        params.put("episodeId", episodeId);
        // 禁忌症信息
        return contraindicationService.CIInfo(Long.valueOf(episodeId), Long.valueOf(entityId));
    }

    @RequestMapping(value = "/reloadDRGInfo")
    @ResponseBody
    public Object reloadDRGInfo(@RequestParam Map<String, Object> params) {
        JSONArray jsonArray = new JSONArray();
        String curEpisodeId = params.get("episodeId").toString();
        JSONObject drgData = new JSONObject();
        if (!CommonUtil.isEmpty(params.get("episodeId"))) {
            Map<String, Object> map = new HashMap<>();
            map.put("xcode", curEpisodeId);
            List<CdcEpisodeEntity> cdcEpisodes = cdcEpisodeService.list(map);
            if (cdcEpisodes.size() == 0) {
                return jsonArray;
            }
            CdcEpisodeEntity episodeEntity = cdcEpisodes.get(0);
            PreGroupWebServiceImplServiceLocator drgLocator = new PreGroupWebServiceImplServiceLocator();
            try {
                String drgUrl = CdcConfigCache.me().getValueByKey("SDS", "float_drg_url");
                PreGroupWebService soap = drgLocator.getPreGroupWebServicePort(drgUrl);
                DRGParams drgParams = sdsDrgParamsService.getDRGParams(episodeEntity);
                String ParamStr = sdsDrgParamsService.combineParamStr(drgParams);
                String backInfo = soap.recGroup(ParamStr);
                JSONObject resultMap = JSON.parseObject(backInfo);
                if (resultMap.get("result_code").equals(-1)){
                    return jsonArray;
                }else if (resultMap.get("result_code").equals(0)){
                    drgData = (JSONObject)resultMap.get("result_data");
                    //费率
                    BigDecimal figure = (BigDecimal) drgData.get("FIGURE");
                    //权重
                    BigDecimal weight = (BigDecimal) drgData.get("WEIGHT");
                    DecimalFormat format = new DecimalFormat("#.#");
                    //极高
                    BigDecimal high = figure.multiply(weight).multiply(new BigDecimal("3"));
                    //级低
                    BigDecimal low = figure.multiply(weight).multiply(new BigDecimal("0.3"));
                    //支付标准
                    BigDecimal stdFee = (BigDecimal) drgData.get("STD_FEE");
                    //总费用
                    BigDecimal payFee = (BigDecimal) drgData.get("TOTAL_EXPENSE");
                    //盈亏
                    BigDecimal profit = stdFee.subtract(payFee);
                    drgData.put("PROFIT",profit);
                    drgData.put("HIGH", new BigDecimal(format.format(high)));
                    drgData.put("LOW",new BigDecimal(format.format(low)));
                }
            }catch (ServiceException | RemoteException e) {
                e.printStackTrace();
            }
        }
        return R.ok().put("data", drgData).put("curEpisodeId", curEpisodeId);
    }

    /**
     * 确认入组病种
     *
     * @param params
     * @return
     */
    @RequestMapping(value = "/confirmInDis")
    @ResponseBody
    public Object confirmInDis(@RequestParam Map<String, Object> params) {
        return this.sdsToolService.confirmInDis(params);
    }

    /**
     * 确认出组或变更病种
     *
     * @param params
     * @return
     */
    @RequestMapping(value = "/confirmOutDis")
    @ResponseBody
    public Object confirmOutDis(@RequestParam Map<String, Object> params) {
        return this.sdsToolService.confirmOutDis(params);
    }

    /**
     * 忽略入组、出组或变更病种
     *
     * @param params
     * @return
     */
    @RequestMapping(value = "/ignoreInOut")
    @ResponseBody
    public Object ignoreInOut(@RequestParam Map<String, Object> params) {
        Long curMrListId = null;
        if (CommonUtil.isNotEmpty(params.get("curMrListId"))) {
            curMrListId = Long.valueOf(params.get("curMrListId").toString());
        }
        Long newDisId = null;
        if (CommonUtil.isNotEmpty(params.get("newDisId"))) {
            newDisId = Long.valueOf(params.get("newDisId").toString());
        }
        Long episodeId = Long.valueOf(params.get("episodeId").toString());
        String modifyUserId = "", modifyUserName="";
        if (CommonUtil.isNotEmpty(params.get("modifyUserId"))) {
            modifyUserName = params.get("modifyUserId").toString();
        }
        if (CommonUtil.isNotEmpty(params.get("modifyUserName"))) {
            modifyUserName = params.get("modifyUserName").toString();
        }
        // 查询数据中心的对应的就诊id
        Map map = new HashMap();
        map.put("xcode", episodeId);
        List<CdcEpisodeEntity> cdcEpisods = cdcEpisodeService.list(map);
        if (cdcEpisods.size() == 0) {
            return R.error();
        }
        CdcEpisodeEntity episodeEntity = cdcEpisods.get(0);
        episodeId = episodeEntity.getId();
        // 修改入组记录
        Date nowDate = new Date();
        if (CommonUtil.isNotEmpty(curMrListId)) {
            // 忽略变更病种
            if (CommonUtil.isNotEmpty(newDisId)) {
                // 新病种手动出组
                SdcBusiQcMrlistEntity sdcBusiQcMrlistEntity = new SdcBusiQcMrlistEntity();
                sdcBusiQcMrlistEntity.setEpisodeId(episodeId);
                sdcBusiQcMrlistEntity.setEntityId(newDisId);
                sdcBusiQcMrlistEntity.setInUserId(String.valueOf(episodeEntity.getAdmDoctorId()));
                sdcBusiQcMrlistEntity.setInLocId(String.valueOf(episodeEntity.getAdmLocId()));
                sdcBusiQcMrlistEntity.setInWardId(String.valueOf(episodeEntity.getAdmWardId()));
                sdcBusiQcMrlistEntity.setInDate(nowDate);
                sdcBusiQcMrlistEntity.setInTime(nowDate);
                sdcBusiQcMrlistEntity.setOutDate(nowDate);
                sdcBusiQcMrlistEntity.setOutTime(nowDate);
                sdcBusiQcMrlistEntity.setState("O");
                sdcBusiQcMrlistEntity.setGroupStatus("ActivePart");
                boolean insert = sdcBusiQcMrlistService.insert(sdcBusiQcMrlistEntity);
                if (insert) {
                    //增加病历状态记录
                    SdcBusiQcMrlislogEntity sdcBusiQcMrlislogEntity = new SdcBusiQcMrlislogEntity();
                    sdcBusiQcMrlislogEntity.setMrlistId(sdcBusiQcMrlistEntity.getId());
                    sdcBusiQcMrlislogEntity.setOperState("O");
                    sdcBusiQcMrlislogEntity.setOperUser(modifyUserName);
                    sdcBusiQcMrlislogEntity.setOperDate(nowDate);
                    sdcBusiQcMrlislogEntity.setOperResume("在院过程质控出组");
                    boolean insert1 = sdcBusiQcMrlislogService.insert(sdcBusiQcMrlislogEntity);
                }
            } else {
                // 忽略出组
                SdcBusiQcMrlistEntity mrList = sdcBusiQcMrlistService.selectById(curMrListId);
                if (mrList != null) {
                    mrList.setGroupStatus("ActivePart");
                    boolean b = sdcBusiQcMrlistService.updateById(mrList);
                }
            }
        } else {
            // 忽略入组
            SdcBusiQcMrlistEntity sdcBusiQcMrlistEntity = new SdcBusiQcMrlistEntity();
            sdcBusiQcMrlistEntity.setEpisodeId(episodeId);
            sdcBusiQcMrlistEntity.setEntityId(newDisId);
            sdcBusiQcMrlistEntity.setInUserId(String.valueOf(episodeEntity.getAdmDoctorId()));
            sdcBusiQcMrlistEntity.setInLocId(String.valueOf(episodeEntity.getAdmLocId()));
            sdcBusiQcMrlistEntity.setInWardId(String.valueOf(episodeEntity.getAdmWardId()));
            sdcBusiQcMrlistEntity.setInDate(nowDate);
            sdcBusiQcMrlistEntity.setInTime(nowDate);
            sdcBusiQcMrlistEntity.setOutDate(nowDate);
            sdcBusiQcMrlistEntity.setOutTime(nowDate);
            sdcBusiQcMrlistEntity.setState("O");
            sdcBusiQcMrlistEntity.setGroupStatus("ActivePart");
            boolean insert = sdcBusiQcMrlistService.insert(sdcBusiQcMrlistEntity);
            if (insert) {
                //增加病历状态记录
                SdcBusiQcMrlislogEntity sdcBusiQcMrlislogEntity = new SdcBusiQcMrlislogEntity();
                sdcBusiQcMrlislogEntity.setMrlistId(sdcBusiQcMrlistEntity.getId());
                sdcBusiQcMrlislogEntity.setOperState("O");
                sdcBusiQcMrlislogEntity.setOperUser(modifyUserName);
                sdcBusiQcMrlislogEntity.setOperDate(nowDate);
                sdcBusiQcMrlislogEntity.setOperResume("在院过程质控出组");
                boolean insert1 = sdcBusiQcMrlislogService.insert(sdcBusiQcMrlislogEntity);
            }
        }
        return R.ok();
    }

    @RequestMapping("saveLog")
    @ResponseBody
    public Object saveSdcBusiLog(@RequestParam Map<String, Object> params) {
        boolean flag = sdcBusiOperationLogService.saveSdcBusiLog(params);
        if (!flag) {
            return R.error();
        }
        return R.ok();
    }

    /**
     * @param params
     * @return
     * @Description: 获取打印表单数据
     * @Title: getPrintInfo
     * @author: zhangdc
     * @date: 2023年03月20日15:08:52
     */
    @RequestMapping(value = "/getPrintInfo")
    @ResponseBody
    public Object getPrintInfo(@RequestParam Map<String, Object> params) {
        return sdsToolService.getPrintInfo(params);
    }

    /**
     * @param params
     * @return
     * @Description: 获取触发来源
     * @Title: getItemKeyFrom
     * @author: zhangdc
     * @date: 2023年04月12日15:08:52
     */
    @RequestMapping(value = "/getItemKeyFrom")
    @ResponseBody
    public Object getItemKeyFrom(@RequestParam Map<String, Object> params) {
        return sdsToolService.getItemKeyFrom(params);
    }

    /**
     * @param
     * @return
     * @Description: 同步诊断数据
     * @Title: synDiagnos
     * @author: zhangdc
     * @date: 2023年04月26日15:08:52
     */
    @RequestMapping(value = "/synDiagnos")
    @ResponseBody
    public Object synDiagnos(@RequestBody DiagnosDataDto jsonDiagnos) {
        JSONArray jsonArray = new JSONArray();
        String curEpisodeId = null;// 记录当前请求参数中的就诊号，以便后续与前台js中就诊号作比较
        if (!CommonUtil.isEmpty(jsonDiagnos.getIDNO())) {
            curEpisodeId =  jsonDiagnos.getIDNO();
            sdsToolService.synDiagnosData(jsonDiagnos);
            // 结果返回结构
            jsonArray = sdsToolService.analysisClinicData2(jsonDiagnos.getIDNO(), jsonDiagnos.getUserName());
        }
        return R.ok().put("data", jsonArray).put("curEpisodeId", curEpisodeId);
    }

    /**
     * @param params
     * @return
     * @Description: 获取单个评估历史
     * @Title: getAsmtNode
     */
    @RequestMapping(value = "/getAsmtNode")
    @ResponseBody
    public Object getAsmtNode(@RequestParam Map<String, Object> params) {
        return sdsToolService.getAsmtNode(params);
    }

}
